package edu.chinasoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import edu.chinasoft.domain.Dept;
import edu.chinasoft.service.DeptService;

import javax.servlet.annotation.WebServlet;

/**
 *
 * @author mhao
 * @date 2020年2月12日:下午3:56:48
 * @version V1.0
 * @Description: 
*/
@WebServlet(name = "myUpdateDeptPageServlet", value = "/servlet/updatedeptpageservlet")
public class UpdateDeptPageServlet extends HttpServlet {
	private static Logger logger = LoggerFactory.getLogger(UpdateDeptPageServlet.class);
	private DeptService deptService;

	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" Servelt01 >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		//获取当前id
		String num = request.getParameter("id");
		int id = Integer.parseInt(num);
		//封装到javaBean
		Dept dept = new Dept();
		dept.setDeptId(id);
		//初始化servelt里关于服务层方法成员变量
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		DeptService deptServiceImp = wac.getBean("deptService", DeptService.class);
		//通过id获取当前的其他信息
		Dept deptById = deptService.selectDeptById(dept);
		HttpSession session = request.getSession();
		session.setAttribute("updateDept", deptById);
		response.sendRedirect(""+request.getContextPath()+"/updatedept.jsp");
		logger.info(" Servelt01 >doGet end.......");
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" Servelt01 >doPost start.......");
		this.doGet(request, response);
		logger.info(" Servelt01 >doPost end.......");
	}

}